//
//  YSLMainViewController.swift
//  SinaWeibo
//
//  Created by 嵩雷 on 16/3/6.
//  Copyright © 2016年 嵩雷. All rights reserved.
//

import UIKit

class YSLMainViewController: UITabBarController {

    override func viewDidLoad() {
        super.viewDidLoad()
//Variable 'self' was written to, but never read
//                                      从未读过
        let tab = YSLMainTabBar()
        tab.composeButtonClosure = { [weak self] in
            print("YSLMainTabBar")
        }
        
        setValue(tab, forKey: "tabBar")
        
        addChildVc()
//        一起设置颜色
        UITabBar.appearance().tintColor = UIColor.orangeColor()
    }
/*
   private func addChildViewController() {
    
    tabBar.tintColor = UIColor.orangeColor()
    let vc = YSLHomeTableViewController()
    vc.title = "首页"
    vc.tabBarItem.image = UIImage(named: "tabbar_home")
    let nav = UINavigationController(rootViewController: vc)

    addChildViewController(nav)
    }
*/
    
//    vc: UIViewController  这里不应该是 UItableViewController?
    private func addChildViewController(vc: UIViewController, title: String, imageNamed: String) {
        
    
        vc.title = title
        vc.tabBarItem.image = UIImage(named: imageNamed)
        vc.tabBarItem.selectedImage = UIImage(named: "\(imageNamed)_selected")
        let nav = UINavigationController(rootViewController: vc)
        addChildViewController(nav)
    }
    
    private func addChildVc() {
        addChildViewController(YSLHomeTableViewController(), title: "首页", imageNamed: "tabbar_home")
        addChildViewController(YSLMessageTableViewController(), title: "消息", imageNamed: "tabbar_message_center")
        addChildViewController(YSLDiscoverTableViewController(), title: "发现", imageNamed: "tabbar_discover")
        addChildViewController(YSLProfileTableViewController(), title: "我", imageNamed: "tabbar_profile")
    }
    
//  Cannot convert value of type 'YSLHomeTableViewController.Type' to expected argument type 'UIViewController'
//    Cannot convert value of type 'YSLHomeTableViewController.Type' to expected argument type 'UITableViewController'


}
